package br.com.single.publico;

import br.com.single.modelo.estoque.Mvmovimeestoqu;
import br.com.single.modelo.estoque.Mvnotafiscal;
import java.util.List;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;

@Entity
@Table(schema = "publico",name = "cdfilial")
@RooJavaBean
@RooToString
@RooJpaActiveRecord(versionField = "", table = "cdfilial", schema = "publico")
@RooDbManaged(automaticallyDelete = true)
public class Cdfilial {

	
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "codigofilial",columnDefinition="codigonumero")
    private Integer codigofilial;

	
	@OneToMany(mappedBy = "filial")
    private Set<Mvmovimeestoqu> mvmovimeestoqus;

	@OneToMany(mappedBy = "filial")
    private Set<Mvnotafiscal> mvnotafiscals;

	@OneToMany(mappedBy = "codigofilial")
    private Set<Cdalmoxa> cdalmoxas;

	@OneToMany(mappedBy = "filialcontab")
    private Set<Cdbanco> cdbancoes;

	@OneToMany(mappedBy = "codigofilial")
    private Set<Cdccusto> cdccustoes;

	@Column(name = "nomefilial",columnDefinition="nomegrande")
    @NotNull
    private String nomefilial;

	@Column(name = "fantasfilial",columnDefinition="nomereduzi")
    @NotNull
    private String fantasfilial;

	@Column(name = "cnpjfilial",columnDefinition="cnpj")
    private String cnpjfilial;

	@Column(name = "iefilial",columnDefinition="ie")
    private String iefilial;

	public Set<Mvmovimeestoqu> getMvmovimeestoqus() {
        return mvmovimeestoqus;
    }

	public void setMvmovimeestoqus(Set<Mvmovimeestoqu> mvmovimeestoqus) {
        this.mvmovimeestoqus = mvmovimeestoqus;
    }

	public Set<Mvnotafiscal> getMvnotafiscals() {
        return mvnotafiscals;
    }

	public void setMvnotafiscals(Set<Mvnotafiscal> mvnotafiscals) {
        this.mvnotafiscals = mvnotafiscals;
    }

	public Set<Cdalmoxa> getCdalmoxas() {
        return cdalmoxas;
    }

	public void setCdalmoxas(Set<Cdalmoxa> cdalmoxas) {
        this.cdalmoxas = cdalmoxas;
    }

	public Set<Cdbanco> getCdbancoes() {
        return cdbancoes;
    }

	public void setCdbancoes(Set<Cdbanco> cdbancoes) {
        this.cdbancoes = cdbancoes;
    }

	public Set<Cdccusto> getCdccustoes() {
        return cdccustoes;
    }

	public void setCdccustoes(Set<Cdccusto> cdccustoes) {
        this.cdccustoes = cdccustoes;
    }

	public String getNomefilial() {
        return nomefilial;
    }

	public void setNomefilial(String nomefilial) {
        this.nomefilial = nomefilial;
    }

	public String getFantasfilial() {
        return fantasfilial;
    }

	public void setFantasfilial(String fantasfilial) {
        this.fantasfilial = fantasfilial;
    }

	public String getCnpjfilial() {
        return cnpjfilial;
    }

	public void setCnpjfilial(String cnpjfilial) {
        this.cnpjfilial = cnpjfilial;
    }

	public String getIefilial() {
        return iefilial;
    }

	public void setIefilial(String iefilial) {
        this.iefilial = iefilial;
    }

	
	public Integer getCodigofilial() {
        return this.codigofilial;
    }

	public void setCodigofilial(Integer id) {
        this.codigofilial = id;
    }

	
	
	
	
	
	@PersistenceContext
    transient EntityManager entityManager;

	public static final EntityManager entityManager() {
        EntityManager em = new Cdfilial().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }

	public static long countCdfilials() {
        return entityManager().createQuery("SELECT COUNT(o) FROM Cdfilial o", Long.class).getSingleResult();
    }

	public static List<Cdfilial> findAllCdfilials() {
        return entityManager().createQuery("SELECT o FROM Cdfilial o", Cdfilial.class).getResultList();
    }

	public static Cdfilial findCdfilial(Integer codigofilial) {
        if (codigofilial == null || codigofilial == 0) return null;
        return entityManager().find(Cdfilial.class, codigofilial);
    }

	public static List<Cdfilial> findCdfilialEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM Cdfilial o", Cdfilial.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }

	@Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }

	@Transactional
    public void remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            Cdfilial attached = Cdfilial.findCdfilial(this.codigofilial);
            this.entityManager.remove(attached);
        }
    }

	@Transactional
    public void flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }

	@Transactional
    public void clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }

	@Transactional
    public Cdfilial merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        Cdfilial merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }
}
